package cn.com.eado.contentproviderdemo;

import android.content.ContentResolver;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    public static final String PICTURE_PATH = "path";
    public static final String DATETIME = "datetime";
    public static final String PLACE_NAME = "place";
    public static final String MAX_TEMP = "maxtemp";
    public static final String MIN_TEMP = "mintemp";

    private ContentResolver contentResolver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //通过contentResolver进行查找
        contentResolver = getContentResolver();
//        Cursor cursor = contentResolver.query(Images.CONTENT_URI, new String[]{Images.PICTURE_PATH, Images.DATETIME, Images.PLACE_NAME, Images.MAX_TEMP, Images.MIN_TEMP}, null, null, null);
        Cursor cursor = contentResolver.query(Images.CONTENT_URI,
                new String[]{Images.PICTURE_PATH, Images.DATETIME, Images.PLACE_NAME, Images.MAX_TEMP, Images.MIN_TEMP},
                "path=?",
                new String[]{"/storage/emulated/0/Yado/camerajpg/C360_2015-11-13-19-35-14-315.jpg"},
                null);
        Log.e("LCY","cursor长度="+cursor.getCount());
        while (cursor.moveToNext()) {
            String s = "存储路径="+cursor.getString(cursor.getColumnIndex(Images.PICTURE_PATH))
                    + "，拍摄时间= "
                    + cursor.getString(cursor.getColumnIndex(Images.DATETIME))
                    + "，拍摄地点= "
                    + cursor.getString(cursor.getColumnIndex(Images.PLACE_NAME))
                    + "，最高温度= "
                    + cursor.getString(cursor.getColumnIndex(Images.MAX_TEMP))
                    + "，最低温度= "
                    + cursor.getString(cursor.getColumnIndex(Images.MIN_TEMP));
            Toast.makeText(this,s,Toast.LENGTH_SHORT).show();
            Log.e("LCY", s);
        }
        cursor.close();
//        startManagingCursor(cursor);  //查找后关闭游标
    }
}
